<?php
namespace Muyuxuan\ThreePayment;
class Manager
{
    protected static $message = "";
    public static function getMessage()
    {
        return self::$message;
    }

    /**
     * 初始化
     * @param $sign bct=宝财通2.0
     * @param $class agent=代理/Payment= 支付
     * @param $config 配置参数
     * @return false|mixed
     */
    public static function make($sign=null,$class="agent",$config=[])
    {
        if(empty($sign)){
            self::$message = "请指定支付渠道";
            return false;
        }
        if(!empty($sign)){
            $sign = strtolower($sign);
        }
        $class = ucfirst($class);
        $dir = __DIR__."/three/{$sign}";
        if(!is_dir($dir)){
            self::$message = "支付渠道不存在";
            return false;
        }
        $classObj = "\\Muyuxuan\\ThreePayment\\three\\{$sign}\\{$class}";
        if(!class_exists($classObj)){
            self::$message = "支付渠道不存在";
            return false;
        }
        return new $classObj($config);
    }
}